package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.AuctionAuctionListParser;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 * 项目名称：ArtworkArt
 * 类名称：AuctionPastAuction_Adapter
 * 类描述：
 * 创建人：耿卫斌
 * 创建时间：2017-3-3 下午5:12:33
 */
public class AuctionPastAuction_Adapter extends BaseAdapter {
    private Context mContext;
    public List<AuctionAuctionListParser> list;

    public AuctionPastAuction_Adapter(Context mContext,
                                      List<AuctionAuctionListParser> list) {
        super();
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(mContext).inflate(R.layout.item_auctionpastauction, null);
            holder.img = (DynamicHeightImageView) v.findViewById(R.id.itemAuctionPastAuction_img);
            holder.state = (TextView) v.findViewById(R.id.itemAuctionPastAuction_state);
            holder.title = (TextView) v.findViewById(R.id.itemAuctionPastAuction_title);
            holder.time = (TextView) v.findViewById(R.id.itemAuctionPastAuction_time);
            holder.num = (TextView) v.findViewById(R.id.itemAuctionPastAuction_num);
            holder.company = (TextView) v.findViewById(R.id.itemAuctionPastAuction_company);
            holder.address = (TextView) v.findViewById(R.id.itemAuctionPastAuction_address);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.img.isRightAngle=true;
        holder.img.setHeight(list.get(position).getHeight());
        Glide.with(mContext).load(list.get(position).getImgurl()
                + "_" + (Integer.parseInt(NetUtils.getDisplayMetrics((Activity) mContext).get(NetUtils.DM_WIDTH)) / 2) + "x10.png"
        ).asBitmap().centerCrop()
                .placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
                .into(new MyBitmapImageViewTarget(holder.img));
        int status = list.get(position).getStatus();
        switch (status) {
            case 0:
                holder.state.setText("已结束");
                break;
            case 1:
                holder.state.setText("待预展");
                break;
            case 2:
                holder.state.setText("预展中");
                break;
            case 3:
                holder.state.setText("拍卖中");
                break;

            default:
                break;
        }

        holder.title.setText(list.get(position).getTitle());
        holder.time.setText(list.get(position).getStart_time() + "-" + list.get(position).getEnd_time());
        if (list.get(position).getLotrecord_num().equals("0"))
            holder.num.setText(list.get(position).getSpecial_num() + "个专场 / " + list.get(position).getLot_num() + "拍品");
        else
            holder.num.setText(list.get(position).getSpecial_num() + "个专场 / " + list.get(position).getLotrecord_num() + "件备案 / " + list.get(position).getLot_num() + "拍品");
        holder.company.setText(list.get(position).getSeller_name());
        holder.address.setText(list.get(position).getAddress());
        return v;
    }

    class ViewHolder {
        DynamicHeightImageView img;
        TextView state, title, time, num, company, address;
    }
}
